<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <script src="./vue.js"></script>
    <title>Document</title>
</head>

<body>
    <!-- 循环使用v-for指令 -->
    <!-- v-for指令需要以 site in sites形式的特殊语法 -->
    <!-- sites是元数据数组并且site是数组元素迭代的别名 -->
    <!-- v-for 可以绑定元素到数组来渲染一个列表 -->
    <div id="app">
        <ol>
            <!-- 类似于 for-in 遍历 -->
            <li v-for="site in sites">{{site.name}}</li>
        </ol>
    </div>

    <script>
        new Vue({
            el: '#app',
            data: {
                sites: [{
                    name: 'Runoob'
                }, {
                    name: "Google"
                }, {
                    name: "Taobao"
                }]
            }
        })
    </script>
</body>

<body>
    <div id="app2">
        <ul>
            <template v-for="site in sites">
                <li>{{site.name}}</li>
                <li>--------------</li>
            </template>
        </ul>
    </div>

    <script>
        new Vue({
            el: "#app2",
            data: {
                sites: [{
                    name: "Runoob"
                }, {
                    name: 'Google'
                }, {
                    name: 'TaoBao'
                }]
            }
        })
    </script>
</body>

<body>
    <!-- v-for 可以通过一个对象的属性来迭代数据 -->
    <div id="app3">
        <ul>
            <li v-for="value in object">
                {{value}}
            </li>
        </ul>
    </div>

    <script>
        new Vue({
            el: '#app3',
            data: {
                object: {
                    name: "菜鸟教程",
                    url: "http://www.runoob.com",
                    slogan: "学的不仅仅是技术，更是梦想"
                }
            }
        })
    </script>
</body>

<body>
    <!-- 提供第二个参数为键名 -->
    <div id="app4">
        <ul>
            <li v-for="(value,key) in object">
                {{key}} : {{value}}
            </li>
        </ul>
    </div>

    <script>
        new Vue({
            el: '#app4',
            data: {
                object: {
                    name: "菜鸟教程",
                    url: "http://www.runoob.com",
                    slogan: "学的不仅仅是技术，更是梦想"
                }
            }
        })
    </script>
</body>

<body>
    <!-- 第三个参数作为索引 -->
    <div id="app5">
        <ul>
            <li v-for="(value,key,index) in object">
                {{index}}.{{key}} : {{value}}
            </li>
        </ul>
    </div>

    <script>
        new Vue({
            el: '#app5',
            data: {
                object: {
                    name: "菜鸟教程",
                    url: "http://www.runoob.com",
                    slogan: "学的不仅仅是技术，更是梦想"
                }
            }
        })
    </script>
</body>

<body>
    <!-- v-for迭代整数 -->
    <div id="app6">
        <ul>
            <li v-for="n in 10">
                {{n}}
            </li>
        </ul>
    </div>

    <script>
        new Vue({
            el: "#app6"
        })
    </script>
</body>

</html>